var mmlog=require("../sever/mmlog").root("[routes/agent.js]");
var express = require('express');
var router = express.Router();
var agent = require("../sever/agent");

/**
 * 坐席连接接口、用于缓存坐席信息 
 */
router.get('/connect/:id', function(req, res, next) {
	var clientId = req.params.id;
	res.json(agent.connect(clientId));
});
router.get('/config/:id', function(req, res, next) {
	var clientId = req.params.id;
	res.json(agent.config(clientId));
});

/**
 * 更新坐席信息 
 */
router.post('/update/info/:jobId', function(req, res, next) {
	var data=req.body;
	agent.service.updateAgentInfo(req.params.jobId,data,function(data){
		res.json(data);
	})
});

/**
 * 创建账号接口 
 */
router.get('/create/:count', function(req, res, next) {
	var count = req.params.count;
	agent.create(count, function(data) {
		res.json({
			path: data
		});
	});
});
/**
 * 个人配置信息接口 
 */
router.post('/config', function(req, res, next) {
	var data = req.body;
	console.log(data);
	var d = agent.accountConfig(data);
	res.json(d);
});

/**
 * 工作状态操纵接口：
 * 1、激活状态
 * 2、负荷状态
 * 3、休眠状态
 * 4、断开状态
 */
router.get('/active/:jobId/:bs', function(req, res, next) {
	var jobId = req.params.jobId,
		bs=req.params.bs;
	res.json(agent.active(jobId,bs));
});
router.get('/full/:jobId', function(req, res, next) {
	var jobId = req.params.jobId;
	res.json(agent.full(jobId));
});
router.get('/sleep/:jobId', function(req, res, next) {
	var jobId = req.params.jobId;
	res.json(agent.sleep(jobId));
});
router.get('/logout/:jobId', function(req, res, next) {
	var jobId = req.params.jobId;
	agent.logout(jobId);
	res.redirect("/login");
});

/**
 * 查询坐席信息接口
 * 1、 all 0 1 2 3 4
 */
router.get('/query/:type', function(req, res, next) {
	var type = req.params.type;
	res.json(agent.query());
});


module.exports = router;